#!/bin/bash

echo "现在开始安装Apache"
echo "下载安装apr"

#安装apr

#DOWNLOND="/var/local/mylamp/download/"


if [ ! -d "${MYLAMP}" ]
then 
  mkdir -p  "${MYLAMP}"
fi

if [ ! -d "${PACKAGE}" ]
then
  mkdir -p "${PACKAGE}"
fi

if [ ! -d "${APACHEDIR}" ]
then
  mkdir -p "${APACHEDIR}"
fi







if [ ! -f "${PACKAGE}apr-1.6.5.tar.gz" ]
then
  wget -P "${PACKAGE}" "http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.gz"
fi
tar -zxvf "${PACKAGE}apr-1.6.5.tar.gz" -C "${PACKAGE}"
cd ${PACKAGE}apr-1.6.5
./configure --prefix=${APACHEDIR}apr/
pwd 
make && make install

# exit  

#安装apr-util
echo "下载安装apr-util"
if [ ! -f "${PACKAGE}apr-util-1.6.1.tar.gz" ]
then
  wget -P "${PACKAGE}" "http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz"   
fi
tar -zxvf "${PACKAGE}apr-util-1.6.1.tar.gz" -C "${PACKAGE}"
cd ${PACKAGE}apr-util-1.6.1
./configure --prefix=${APACHEDIR}apr-util/ --with-apr=${APACHEDIR}apr/
make && make install


#安装pcre
echo "下载安装pcre"
if [ ! -f "${PACKAGE}pcre-8.42.tar.gz" ]
then
  wget -P "${PACKAGE}" "http://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz"
fi

tar -zxvf "${PACKAGE}pcre-8.42.tar.gz" -C "${PACKAGE}"
cd ${PACKAGE}pcre-8.42
./configure --prefix=${APACHEDIR}pcre/  
make && make install


#安装httpd
echo "下载安装httpd"
if [ ! -f "${PACKAGE}httpd-2.4.37.tar.gz" ]
then
  wget -P "${PACKAGE}" "http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.37.tar.gz"
fi

tar -zxvf "${PACKAGE}httpd-2.4.37.tar.gz" -C "${PACKAGE}" 
cd ${PACKAGE}httpd-2.4.37
./configure --prefix=${APACHEDIR}httpd/ --with-apr=${APACHEDIR}apr/ --with-apr-util=${APACHEDIR}apr-util/ --with-pcre=${APACHEDIR}pcre/  
make && make install



cd ${HERE}
cp -r ${APACHEDIR}httpd/htdocs  ${MYLAMP}www
#执行py脚本，操作配置文件
python ./chghttpdconf.py -c ${APACHEDIR}httpd/conf/httpd.conf #我的www目录




